/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
        this.cargarMapa(-32.9509953,-60.6559091,12);
        this.buscar();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    calcularCercanos: function(){
        var keycode = (event.keyCode ? event.keyCode : event.which);
	if(keycode == '13'){
		alert('You pressed a "enter" key in textbox');	
	}
    },
    bindEvents: function() {
        $("#direccion").bind("keypress", function(){
            app.calcularCercanos();
        });
        $("#lab-servicio").hide();
        $("#serv").bind("click", function(){
            app.alargar();
            $("#lat-der").hide();
        });
        $(".comboSelect").bind("change", function(){
            app.achicar();
            var a = $(".comboSelect option:selected").attr("id");
            $("#lat-der").show();
            app.cargarImagen(a);
            $(".comboSelect").val("0");
        });
        $(".comboSelect").bind("close", function(){
            app.achicar();
        });
    },
    cargarMapa: function(lat, lon, zoom) {
         var mapOptions = { center: new google.maps.LatLng(lat, lon), 
                            zoom: zoom, 
                            mapTypeId: google.maps.MapTypeId.ROADMAP,
                            zoomControl:true,
                            zoomControlOptions: {
                                position: google.maps.ControlPosition.TOP_LEFT
                            },
                            disableDefaultUI: true
                          };
         var map = new google.maps.Map(document.getElementById("mapa"), mapOptions);
    },
    alargar: function(){
        $("#serv").animate({
            width: "90%"
        }, 300, function() {
          $("#serv").hide();
          $("#lab-servicio").show();
        });
        
    },
    achicar: function(){
        $("#lab-servicio").animate({
            
        }, 400, function() {
          var serv = $("#serv");
          $("#lab-servicio").hide();
          serv.css("width", "20px");
          serv.show();
        });
    },
    cargarImagen: function(id){
        alert(id);
    },
    buscar: function(){       
        $.ajax({
         url: "http://localhost:8080/NextToMe/buscarMobile",
         jsonpCallback: "jpCallback",
         dataType: "jsonp",
         type: "GET",
         crossDomain: true,
         data: "serv=1&dir=montevideo+500",
         success: function(jsondata) {   
             console.log(jsondata);
         },
         error: function (jqXHR, textStatus, errorThrown) {
             console.log('ENtre');
         }
        });
        function jpCallback(a){
              console.log('hola');
        }
    }
};
